package com.bnq.face

import android.app.Activity

class BrightnessHelper(private val activity: Activity) {
    private var previousBrightness: Float? = null

    /** 设置窗口亮度为最大（1.0f） */
    fun setMaxBrightness() {
        val lp = activity.window.attributes
        if (previousBrightness == null) {
            previousBrightness = lp.screenBrightness
        }
        lp.screenBrightness = 1.0f
        activity.window.attributes = lp
    }

    /** 恢复之前保存的亮度 */
    fun restoreBrightness() {
        previousBrightness?.let { value ->
            val lp = activity.window.attributes
            lp.screenBrightness = value
            activity.window.attributes = lp
            previousBrightness = null
        }
    }
}
